//相向双指针
class Solution {
public:
    int trap(vector<int>& height) {
        int n=height.size();
        int ans=0, pre=0, suf=0;
        int left=0, right=n-1;
        while(left<right)
        {
            pre=max(pre, height[left]);
            suf=max(suf, height[right]);
            ans+=pre<suf?pre-height[left++]:suf-height[right--]; //谁小移动谁
        }
        return ans;
    }
};